package com.pangus.ims.mes.controller;
import java.util.HashMap;
/*
 * 数据库表MES_MO_CUST_DRIVER_LOG对应的Controller
 */
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.pangus.LogConstants;
import com.pangus.PangusConstants;
import com.pangus.common.dto.EditDataResult;
import com.pangus.common.dto.EditResult;
import com.pangus.common.dto.JqGridRequest;
import com.pangus.common.dto.JqGridResponse;
import com.pangus.common.dto.JsonRequest;
import com.pangus.common.sys.dto.domain.LogDto;
import com.pangus.common.sys.utils.CommonUtils;
import com.pangus.common.sys.utils.ParamUtils;
import com.pangus.fa.controller.BaseController;
import com.pangus.ims.mes.dto.domain.MesMoCustDriverLogDto;
import com.pangus.ims.mes.dto.domain.MesProdExchConfigDto;
import com.pangus.ims.mes.form.MesMoCustDriverLogForm;
import com.pangus.ims.mes.service.MesMoCustDriverLogService;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;


@RestController
@RequestMapping("/mesmocustdriverlog")
public class MesMoCustDriverLogController extends BaseController {
	
	@Autowired
	private MesMoCustDriverLogService mesMoCustDriverLogService;
	
	@ApiOperation(value = "跳转", hidden = true)
	@RequestMapping(value = { "/{path}" }, method = RequestMethod.GET)
	public ModelAndView path(HttpServletRequest request, @PathVariable String path,
			@RequestParam(value = "id", required = false) String id,
			@RequestParam(value = "type", required = false) String type) {
		ModelAndView modelAndView = new ModelAndView("mes/mesmocustdriverlog/" + path);
		modelAndView.addObject("type", type);
		modelAndView.addObject("id", id);
		logger.info("/mesmocustdriverlog/" + path);
		return modelAndView;
	}
	
	
	@ApiOperation(value = "查询列表")
	@ApiImplicitParam(value = "需要查询的条件", required = false, dataType = "JqGridRequest<MesMoCustDriverLogForm>", defaultValue = "default")
	@RequestMapping(value = "/query", method = RequestMethod.POST)
	public JqGridResponse<MesMoCustDriverLogForm> query(@RequestBody JqGridRequest<MesMoCustDriverLogForm> jqrequest,HttpServletRequest request) {
		logger.info("/mesmocustdriverlog/query:" + jqrequest);
		ParamUtils paramUtils = new ParamUtils(request);
		JqGridResponse<MesMoCustDriverLogForm> jqResponse = mesMoCustDriverLogService.query(jqrequest, paramUtils);
		formUtils.fillForms(jqResponse.getData());
		return jqResponse;
	}

	@ApiOperation(value = "查询单个对象")
	@ApiImplicitParam(value = "需要查询的条件", required = false, dataType = "MesMoCustDriverLogForm", defaultValue = "default")
	@RequestMapping(value = "/getById")
	public EditDataResult<MesMoCustDriverLogForm> getById(@RequestBody MesMoCustDriverLogForm mesMoCustDriverLogForm, HttpServletRequest request) {
		ParamUtils paramUtils = new ParamUtils(request, new LogDto(request));
		EditDataResult<MesMoCustDriverLogForm> result = mesMoCustDriverLogService.getById(mesMoCustDriverLogForm, paramUtils);
		formUtils.fillForm(result.getData());
		return result;
	}
	

	@ApiOperation(value = "新增")
	@ApiImplicitParam(name = "MesMoCustDriverLogForm", value = "需要新增的对象", required = true, dataType = "MesMoCustDriverLogForm")
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public EditDataResult<MesMoCustDriverLogForm> add(@RequestBody JsonRequest<MesMoCustDriverLogForm> jsonRequest,
			HttpServletRequest request) {
		ParamUtils paramUtils = new ParamUtils(request, new LogDto(request, LogConstants.LOG_TYPE_A));
		EditDataResult<MesMoCustDriverLogForm> result = mesMoCustDriverLogService.add(jsonRequest, paramUtils);
		insertByRequest(request, paramUtils.getLogDto(), result.getData(), result.getData().getMoId()); // 写入日志
		return result;
	}

	@ApiOperation(value = "修改")
	@ApiImplicitParam(name = "MesMoCustDriverLogForm", value = "需要修改的对象", required = true, dataType = "MesMoCustDriverLogForm")
	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	public EditDataResult<MesMoCustDriverLogForm> edit(@RequestBody JsonRequest<MesMoCustDriverLogForm> jsonRequest,
			HttpServletRequest request) {
		ParamUtils paramUtils = new ParamUtils(request, new LogDto(request, LogConstants.LOG_TYPE_E));
		EditDataResult<MesMoCustDriverLogForm> result = mesMoCustDriverLogService.edit(jsonRequest, paramUtils);
		insertByRequest(request, paramUtils.getLogDto(), result.getData(), result.getData().getMoId()); // 写入日志
		return result;
	}

	@ApiOperation(value = "删除")
	@ApiImplicitParam(name = "MesMoCustDriverLogDto", value = "需要删除的对象", required = true, dataType = "JsonRequest<MesMoCustDriverLogDto>")
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public EditDataResult<MesMoCustDriverLogDto> delete(@RequestBody JsonRequest<List<MesMoCustDriverLogDto>> mesMoCustDriverLogDtoList, HttpServletRequest request) {
		ParamUtils paramUtils = new ParamUtils(request, new LogDto(request, LogConstants.LOG_TYPE_D));
		EditDataResult<MesMoCustDriverLogDto> result = mesMoCustDriverLogService.delete(mesMoCustDriverLogDtoList.getForm(), paramUtils);
		insertByRequest(request, paramUtils.getLogDto(), mesMoCustDriverLogService,CommonUtils.getListValueByKey(mesMoCustDriverLogDtoList.getForm(), "moId", MesMoCustDriverLogDto.class)); // 写入日志
		return result;
	}

	@ResponseBody
	@RequestMapping("/exportExcel")
	public void exportExcel(HttpServletRequest request) {
		exportExcel(MesMoCustDriverLogDto.class, mesMoCustDriverLogService);
	}

	@ResponseBody
	@RequestMapping("/importExcel")
	public void importExcel(@RequestParam("file") MultipartFile[] files, HttpServletRequest request) {
		importExcel(MesMoCustDriverLogForm.class, mesMoCustDriverLogService, files);
	}
	
	@ResponseBody
    @RequestMapping(value = "/readExcel", method = RequestMethod.POST)
    public EditResult parseExcel1(MultipartFile file,@RequestParam(value = "reParam", required = false) String[] reParam,
    		@RequestParam(value = "extend", required = false) String extend,
    		@RequestParam(value = "bomStartSeq", required = false) String bomStartSeq,
    		HttpServletRequest request) throws Exception{
		return parseExcel(file, reParam, extend, bomStartSeq, request);
   	}
    
    @ResponseBody
	@RequestMapping(value = "/verifyExcel")
	public EditResult checkField(@RequestBody JsonRequest<MesMoCustDriverLogForm> jsonRequest, HttpServletRequest request){
    	EditResult result = new EditResult();
    	try{
    		result = checkField(MesMoCustDriverLogForm.class,mesMoCustDriverLogService,jsonRequest);
    	}catch(Exception e){
    		e.printStackTrace();
    	}
		return result;
	}
    
    @RequestMapping(value = "/insertExcel", method = RequestMethod.POST)
	public EditResult insertExcel(@RequestBody JsonRequest<MesMoCustDriverLogForm> jsonRequest, HttpServletRequest request) throws Exception{
    	EditResult result = new EditResult();
    	try{
    		result = insertExcel(MesMoCustDriverLogForm.class,mesMoCustDriverLogService,jsonRequest,request);
    	}catch(Exception e){
    		e.printStackTrace();
    	}
		return result;
	}
	

	
	
}
